<?php
/**
 * Created by PhpStorm.
 * User: jx
 * Date: 2018-03-22
 * Time: 21:35
 */

namespace app\common\logic;
use think\Model;

use app\common\logic\Logic;
use app\common\model\Type;
use app\common\model\SpecValue;

class SpecLogic extends Logic
{
    protected $modelClass = 'app\common\model\Spec';
    protected $column = 'type_id,type_title,id,name,is_attr';
    protected $order = 'id desc';
    
    public function add($params){
        $type = Type::where('id',$params['type_id'])->field('id,title')->find();
        if(!$type){
            exception('对应的商品type不存在');
        }
        $params['type_title'] = $type['title'];
        $id = parent::add($params);
        return $id;
    }
    

    
    /**
     * @param $params
     * 属性太简单了，都是批量加的咯。。。,而且这个方法只有后台用的到，不用ajax返回太幸福了
     */
    public function addVals($params){
        
        $model = new SpecValue();
        $ids = $model->allowField(true)->saveAll($params);
        return $ids;

    }

  

}